package com.baijiaoxi.utils.email;

import lombok.Data;
import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;

@Data
public class EmailConfig {
    private String host = "smtp.163.com";
    private Integer port = 465;
    private String username = "";
    private String password = "";
    private String eamilFrom = "";
    private String eamilFromName = "";
    private String timeout = "25000";
    private String protocol = "smtp";//smtp 或 exchange
    /**
     * exchange版本
     */

    private ExchangeVersion exchangeVersion = ExchangeVersion.Exchange2007_SP1;
    /**
     * exchange domain 一般为空
     */

    private String domain = null;

    public EmailConfig() {
    }

    public EmailConfig(String HOST, Integer PORT, String USERNAME, String PASSWORD, String EMAILFORM, String EMAILFORMNAME, String timeout) {
        this.host = HOST;
        this.port = PORT;
        this.username = USERNAME;
        this.password = PASSWORD;
        this.eamilFrom = EMAILFORM;
        this.eamilFromName = EMAILFORMNAME;
        this.timeout = timeout;
    }

    public EmailConfig setProtocol(String protocol) {
        this.protocol = protocol;
        return this;
    }

    /**
     * Exchange2007_SP1,
     * Exchange2010,
     * Exchange2010_SP1,
     * Exchange2010_SP2;
     *
     * @param exchangeVersion
     * @return
     */
    public EmailConfig setExchangeVersion(String exchangeVersion) {
        if (exchangeVersion != null)
            switch (exchangeVersion) {
                case "Exchange2007_SP1" -> {
                    this.exchangeVersion = ExchangeVersion.Exchange2007_SP1;
                }
                case "Exchange2010" -> {
                    this.exchangeVersion = ExchangeVersion.Exchange2010;
                }
                case "Exchange2010_SP1" -> {
                    this.exchangeVersion = ExchangeVersion.Exchange2010_SP1;
                }
                case "Exchange2010_SP2" -> {
                    this.exchangeVersion = ExchangeVersion.Exchange2010_SP2;
                }
                default -> {
                    this.exchangeVersion = ExchangeVersion.Exchange2007_SP1;
                }
            }
        else this.exchangeVersion = ExchangeVersion.Exchange2007_SP1;
        return this;
    }

    public EmailConfig setHost(String host) {
        this.host = host;
        return this;
    }

    public EmailConfig setPort(Integer port) {
        this.port = port;
        return this;
    }

    public EmailConfig setUsername(String username) {
        this.username = username;
        return this;
    }

    public EmailConfig setPassword(String password) {
        this.password = password;
        return this;
    }

    public EmailConfig setEamilFrom(String eamilFrom) {
        this.eamilFrom = eamilFrom;
        return this;
    }

    public EmailConfig setEamilFromName(String eamilFromName) {
        this.eamilFromName = eamilFromName;
        return this;
    }

    public EmailConfig setTimeout(String timeout) {
        this.timeout = timeout;
        return this;
    }
}
